import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/fenxiao/customer/list',
  save= '/fenxiao/customer/add',
  edit= '/fenxiao/customer/edit',
  deleteOne = '/fenxiao/customer/delete',
  deleteBatch = '/fenxiao/customer/deleteBatch',
  importExcel = '/fenxiao/customer/importExcel',
  exportXls = '/fenxiao/customer/exportXls',
  customerFollowupList = '/fenxiao/customer/listCustomerFollowupByMainId',
  customerFollowupSave= '/fenxiao/customer/addCustomerFollowup',
  customerFollowupEdit= '/fenxiao/customer/editCustomerFollowup',
  customerFollowupDelete = '/fenxiao/customer/deleteCustomerFollowup',
  customerFollowupDeleteBatch = '/fenxiao/customer/deleteBatchCustomerFollowup',
  contractList = '/fenxiao/customer/listContractByMainId',
  contractSave= '/fenxiao/customer/addContract',
  contractEdit= '/fenxiao/customer/editContract',
  contractDelete = '/fenxiao/customer/deleteContract',
  contractDeleteBatch = '/fenxiao/customer/deleteBatchContract',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}
  
/**
 * 列表接口
 * @param params
 */
export const customerFollowupList = (params) => {
  if(params['customerId']){
    return defHttp.get({ url: Api.customerFollowupList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const customerFollowupDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.customerFollowupDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const customerFollowupDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.customerFollowupDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  customerFollowupSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.customerFollowupEdit : Api.customerFollowupSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const customerFollowupImportUrl = '/fenxiao/customer/importCustomerFollowup'

/**
 * 导出
 */
export const customerFollowupExportXlsUrl = '/fenxiao/customer/exportCustomerFollowup'
  
/**
 * 列表接口
 * @param params
 */
export const contractList = (params) => {
  if(params['customerId']){
    return defHttp.get({ url: Api.contractList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const contractDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.contractDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const contractDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.contractDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  contractSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.contractEdit : Api.contractSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const contractImportUrl = '/fenxiao/customer/importContract'

/**
 * 导出
 */
export const contractExportXlsUrl = '/fenxiao/customer/exportContract'
